<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8"/>
    <title>景点列表</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" th:href="@{/layuiadmin/layui/css/layui.css}"  media="all">
    <link rel="stylesheet" th:href="@{/layuiadmin/style/admin.css}" media="all">
    <script src="https://code.jquery.com/jquery-3.1.1.min.js"></script>
</head>
<body>

<div class="layui-fluid">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-header">动态列表</div>
                <div class="layui-card-body">

                    <!--<form class="layui-form">-->
                    <!--<div class="layui-input-inline">-->
                    <!--<input type="tel" name="searContent" autocomplete="off"-->
                    <!--placeholder="输入景点名字" class="layui-input">-->
                    <!--</div>-->
                    <!--<div class="layui-input-inline " style="width: 90px">-->
                    <!--<button class="layui-btn" id="searchEmailCompany" data-type="reload">-->
                    <!--<i class="layui-icon" style="font-size: 20px; "></i> 搜索-->
                    <!--</button>-->
                    <!--</div>-->
                    <!--</form>-->


                    <table class="layui-hide" id="test-table-reload" lay-filter="test-table-reload"></table>

                    <script type="text/html" id="barlist">
                        <a class="layui-btn layui-btn-xs" lay-event="edit">审核</a>
                        <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
                    </script>
                </div>
            </div>
        </div>
    </div>
</div>

<script th:src="@{/layuiadmin/layui/layui.js}"></script>
<script>
    layui.use('table', function(){
        var table = layui.table;
        //方法级渲染
        table.render({
            elem: '#test-table-reload'
            ,url: 'http://localhost:8080/article'
            ,cols: [
                [
                    {checkbox: true, fixed: true}
                    ,{field:'topic', title: '主题', width:180, align:'center', edit: 'text'}
                    ,{field:'createBy', title: '作者', width:100, align:'center', edit: 'text'}
                    ,{field:'status', title: '状态', width:100, align:'center',
                    templet:function (d) {
                        if (d.status == 0){
                            return "未审核";
                        }else {
                            return "审核通过";
                    }}
                      }
                    ,{field:'articleType', title: '类别', width:100, align:'center',
                    templet:function (d) {
                        if (d.articleType == 'scenic'){
                            return "景点";
                        }else if (d.articleType == 'hotel') {
                            return "酒店";
                        }else{
                            return "";
                        }
                    }
                   }
                    ,{field:'content', title: '内容',width:200, align:'center',event: 'setSign', style:'cursor: pointer;'}
                    ,{field:'picture', title: '图片', width:180, align:'center',event: 'setSign', style:'cursor: pointer;'}
                    ,{width:136, title:'操作', align:'center', toolbar: '#barlist'}
                ]
            ]
            ,page: true
            ,height: 470
            ,id: 'testReload'
        });

        //监听工具条
        table.on('tool(test-table-reload)', function(obj){
            var data = obj.data;

            if(obj.event === 'detail'){
                layer.msg('ID：'+ data.id + ' 的查看操作');
            } else if(obj.event === 'del'){
                layer.confirm('真的删除行么', function(index){
                    obj.del();
                    layer.close(index);
                    $.ajax({
                        type: "DELETE",
                        url: "/article/"+ data.id ,
                        data: {"id": data.id},
                        dataType: "json",
                        contentType: "application/json;charset=utf-8",
                        success: function(result) {
                            if(result.code == 0) {
                                layer.msg(result.message,{icon: 1});
                            } else {
                                layer.msg(result.message, {
                                    icon: 5
                                });
                            }
                        }
                    });
                });
            } else if(obj.event === 'edit'){
                    $.ajax({
                        type: "PUT",
                        url: "/article/"+ data.id ,
                        dataType: "json",
                        contentType: "application/json;charset=utf-8",
                        success: function(result) {
                            if(result.code == 0) {
                                layer.msg(result.message,{icon: 1});
                            } else {
                                layer.msg(result.message, {
                                    icon: 5
                                });
                            }
                        }
                    });

            }
        });

        // // 点击获取数据
        // var  active = {
        //     getInfo: function () {
        //                var fileName=$('#test-table-demoReload').val();
        //                // var startTime=$('#startTime').val();
        //                // var endTime=$('#endTime').val();
        //                if ($('#fileName').val()) {
        //                      var index = layer.msg('查询中，请稍候...',{icon: 16,time:false,shade:0});
        //                      setTimeout(function(){
        //                          table.reload('flinklist', {
        //                             where: {
        //                                 'fileName':fileName,
        //                                 'timeRange':timeRange
        //                             }
        //                          });
        //                         layer.close(index);
        //                      },800);
        //                  } else {
        //                      table.reload('flinklist', {where: {
        //                             'fileName':fileName,
        //                             'timeRange':timeRange
        //                        }});
        //                   table.reload('')
        //                 }
        //             },
        //     };


        //搜索加载--数据表格重载
        var $ = layui.$, active = {
            reload: function () {
                //执行重载
                table.reload('userTables', {
                    page: {
                        curr: 1 //重新从第 1 页开始
                    }
                    , where: {
                        searContent: $("input[name=searContent]").val()
                    }
                });
            }
        };





        $('.test-table-reload-btn .layui-btn').on('click', function(){
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });

    });
</script>
</body>
</html>